package com.gale.park.modules.pms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gale.park.common.api.CommonPage;
import com.gale.park.common.api.CommonResult;
import com.gale.park.modules.pms.dto.TempDTO;
import com.gale.park.modules.pms.model.PmsTemp;
import com.gale.park.modules.pms.service.PmsTempService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Gale
 * @since 2022-02-16
 */
@RestController
@RequestMapping("/temp")
public class PmsTempController {

    @Autowired
    private PmsTempService tempService;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation("临时车辆列表")
    public CommonResult<CommonPage<PmsTemp>> list(@RequestBody TempDTO temp) {
        Page<PmsTemp> page = tempService.list(temp);

        return CommonResult.success(CommonPage.restPage(page));

    }

    @RequestMapping(value = "/entry/{carNum}", method = RequestMethod.GET)
    @ApiOperation("临时车辆进场")
    public CommonResult entryParking(@PathVariable String carNum) {

        boolean result = tempService.entryParking(carNum);

        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

    @RequestMapping(value = "/out/{tempId}", method = RequestMethod.POST)
    @ApiOperation("临时车辆出场")
    public CommonResult outParking(@PathVariable String tempId) {

        boolean result = tempService.outParking(tempId);

        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

    @RequestMapping(value = "/tempInfo/{tempId}", method = RequestMethod.GET)
    @ApiOperation("获取临时车辆信息")
    public CommonResult getTempInfo(@PathVariable String tempId) {
        PmsTemp temp = tempService.getTempById(tempId);
        return CommonResult.success(temp);
    }

    @RequestMapping(value = "settlement/{tempId}/{money}")
    @ApiOperation("临时车辆费用结算")
    public CommonResult settlement(@PathVariable String tempId,
                                   @PathVariable Float money) {

        boolean result = tempService.settlement(tempId,money);

        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

    @RequestMapping(value = "delete/{tempId}", method = RequestMethod.DELETE)
    @ApiOperation("临时车辆删除")
    public CommonResult delete(@PathVariable String tempId) {

        boolean result = tempService.delete(tempId);

        if (result) {
            return CommonResult.success(result);
        } else {
            return CommonResult.failed();
        }
    }

}

